<script setup lang="ts">
import { RouterView } from 'vue-router'
import { useUserStore } from './stores/user'
import { onMounted } from 'vue'

const userStore = useUserStore()

onMounted(async () => {
  console.log('App.vue 初始化，当前用户状态:', {
    isLoggedIn: userStore.isLoggedIn,
    hasToken: !!userStore.token,
    hasUser: !!userStore.currentUser
  })
  
  // 如果有token但没有用户信息，尝试获取
  if (userStore.token && !userStore.currentUser) {
    try {
      console.log('检测到token但无用户信息，尝试获取用户数据...')
      await userStore.getCurrentUser()
    } catch (error) {
      console.error('获取用户信息失败:', error)
      // 如果获取失败，清除状态
      userStore.logout()
    }
  }
})
</script>

<template>
  <div id="app">
    <router-view />
  </div>
</template>

<style>
#app {
  font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  margin: 0;
  padding: 0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background-color: #f5f7fa;
}
</style>
